package zhoufu.sz.sanxiao_check.ui.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.widget.TextView;
import java.util.List;
import org.byteam.superadapter.recycler.BaseViewHolder;
import org.byteam.superadapter.recycler.SuperAdapter;
import zhoufu.sz.sanxiao_check.R;
import zhoufu.sz.sanxiao_check.models.StreetListModel;
import zhoufu.sz.sanxiao_check.utils.UIUtils;

/**
 * User:RCP
 * email:ruancaipu@gmail.com
 * Date:2016/7/21
 */
public class StreetAdapter extends SuperAdapter<StreetListModel>
{
    public StreetAdapter(Context context,
            List<StreetListModel> items, int layoutResId)
    {
        super(context, items, layoutResId);
    }

    @Override public void onBind(int viewType, BaseViewHolder holder, int position,
            StreetListModel item)
    {
        holder.setText(R.id.mStreetName, TextUtils.isEmpty(item.getSID()) ? "空铺" : item.getName());
        holder.setText(R.id.mStreetOperator, item.getRun_Name() + "  " + item.getRun_Phone());
        holder.setText(R.id.mStreetTime, item.getExaminTime());
        holder.setText(R.id.mStreetAddress, item.getAddress());
        holder.setText(R.id.mStreetIcon, item.getGrade());
        if ( !TextUtils.isEmpty(item.getGrade()) )
        {
            switch (item.getGrade())
            {
                case "A":
                    holder.setBackgroundRes(R.id.mStreetIcon, R.drawable.shape_oval_backpage_green);
                    break;
                case "B":
                    holder.setBackgroundRes(R.id.mStreetIcon,
                            R.drawable.shape_oval_backpage_yellow);
                    break;
                case "C":
                    holder.setBackgroundRes(R.id.mStreetIcon, R.drawable.shape_oval_backpage_red);
                    break;
                default:
                    holder.setText(R.id.mStreetIcon, "空");
                    holder.setBackgroundRes(R.id.mStreetIcon, R.drawable.shape_oval_backpage_gray);
                    break;
            }
        } else
        {
            holder.setText(R.id.mStreetIcon, "空");
            holder.setBackgroundRes(R.id.mStreetIcon, R.drawable.shape_oval_backpage_gray);
        }
        TextView state   = holder.getView(R.id.mStreetState);
        TextView nextDay = holder.getView(R.id.mStreetNextDay);
        if ( TextUtils.isEmpty(item.getIsCheck()) || "0".equals(item.getIsCheck()) || TextUtils
                .isEmpty(item.getSID()) )
        {
            state.setText("未检查");
            state.setTextColor(UIUtils.getColor(R.color.line_gray));
            nextDay.setText("");
        } else
        {
            state.setText("已检查");
            state.setTextColor(UIUtils.getColor(R.color.colorPrimary));
            if ( item.getNextDay() < 0 )
            {
                nextDay.setText("逾期");
                nextDay.setTextColor(UIUtils.getColor(R.color.grade_c));
            } else if ( item.getNextDay() == 0 )
            {
                nextDay.setText("今天");
                nextDay.setTextColor(UIUtils.getColor(R.color.grade_c));
            } else
            {
                nextDay.setText(UIUtils.getString(R.string.street_next_day, item.getNextDay()));
                nextDay.setTextColor(UIUtils.getColor(R.color.grade_a));
            }
        }
    }
}
